<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Hash;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class CollectController extends Controller
{
    public function getSc(Request $request)
    {
    	// dd(222);
    	//接收id
        $id = $request->input('id');
        //查询数据库
        $res = DB::table('goods')->where('id',$id)->first();
        $data['price'] = $res->price;
        $data['proname'] = $res->goodname;
        $data['img'] = $res->goodpic;
        $data['userid'] = session('id');
        // dd($data);
        if (session('id')) {
        $der = DB::table('collect')->insert($data);
        }else{
            return redirect('/log/log/log')->with('error','请先登录');
        }

        return view('geren.success');

	}
		//将数据库中数据遍历出来
    	public function getCollect()
    	{
		    $did = DB::table('collect')->get();
             
            // dd($did);
            $lianjie = IndexController::listss();
            return view('comment.collect',['bian'=>$did,'lianjie'=>$lianjie]);
      
    	}

    	public function getDel($id)
    	{
                // dd($id);
    		$dell = DB::table('collect')->where('id',$id)->delete();
    	if($dell){
    		//成功 重定向 页面跳转到列表页
    		return redirect('/del/collect')->with('success','商品取消收藏成功');
    	}else{
    		//失败 回到添加页
    		return back()->with('error','商品取消收藏失败');
    	}

    	}

        
}
